/**
* File: War3Source_RogueWizard.sp
* Description: Wizard race of warcraft.
* Author: Lucky 
*/
 
#pragma semicolon 1
 
#include <sourcemod>
#include "W3SIncs/War3Source_Interface"
#include <sdktools>
#include <sdktools_functions>
#include <sdktools_tempents>
#include <sdktools_tempents_stocks>
#include <sdkhooks>

new thisRaceID;
new MoneyOffsetCS;
new m_vecBaseVelocity;

//Frost
new FrostCost[7]={0,1500,1750,2000,2250,2500,2750};
new FrostDamage[7]={0,5,7,9,11,13,15};
new Float:FrostEff[7]={1.0,0.9,0.8,0.7,0.6,0.5,0.4};
//new const Float:FrostTime=5.0;
new bool:bOrb[MAXPLAYERS];
new Float:bSpeedUp[MAXPLAYERS];
new Float:bSpeedDown[MAXPLAYERS];
new Float:bAttack[MAXPLAYERS];

//Fire
new FireCost[8]={0,3000,3750,4500,5250,6000,6750,7500};
new FireDamage[8]={0,30,35,40,45,50,55,60};
new Float:FireTime[8]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0};

//Lightning
new LightningCost[9]={0,3000,4000,5000,6000,7000,8000,9000,10000};
new LightningDamage[9]={0,10,15,20,25,30,35,40,45};
new Float:LightningDistance[9]={0.0,450.0,500.0,550.0,600.0,650.0,700.0,750.0,800.0};
new bool:bBeenHit[MAXPLAYERS][MAXPLAYERS];

//Tornado
new TornadoCost[8]={0,1500,2000,2500,3000,3500,4000,4500};
new Float:TornadoTime[8]={0.0,1.0,1.5,2.0,2.5,3.0,3.5,4.0};
new TornadoRange[8]={0,200,300,400,500,600,700,800};

//Training
new Float:Cooldown[9]={30.0,24.0,22.0,20.0,18.0,16.0,14.0,12.0,10.0};
new MoneyGain[9]={100,150,200,250,300,350,400,450,500};
new MoneyMax[9]={16000,20000,25000,30000,35000,40000,45000,50000,55000};

//Mana Shield
new Float:ShieldChance[7]={0.0,0.3,0.4,0.5,0.6,0.7,0.8};
new DamageDeplete[7]={0,200,180,160,140,120,100};
new Float:DamageReducer[7]={0.0,0.90,0.82,0.74,0.66,0.58,0.50};
new bShield[MAXPLAYERS];

//Magical Pressure
new bool:bIsPressure[MAXPLAYERS];
new bool:bWasPressure[MAXPLAYERS];
new Float:PressureTime[6]={0.0,4.0,5.0,6.0,7.0,8.0};
new const PressureMana=1000;
new const PressureHealth=5;

new BurnSprite, ShieldSprite;
new BeamSprite,HaloSprite;
new String:frost[]="war3source/roguewizard/Frost.wav";
new String:fire[]="war3source/roguewizard/Fire.wav";
new String:shield[]="war3source/roguewizard/Shield.wav";
new String:tornado[]="war3source/roguewizard/Tornado.wav";
new String:lightning[]="war3source/roguewizard/Lightning.wav";
new String:pressure[]="war3source/roguewizard/Avatar.wav";

//Skills & Ultimate
new SKILL_TRAINING, SKILL_SHIELD, SKILL_FROST, SKILL_LIGHTNING,SKILL_TORNADO,SKILL_FIREBALL,ULT_PRESSURE;
 
public Plugin:myinfo = 
{
	name = "War3Source Race - Rogue Wizard",
	author = "Lucky",
	description = "Wizard race of warcraft",
	version = "alpha",
	url = "http://warcraft-source.net/forum/index.php?topic=371.0"
}

public OnPluginStart()
{
	CreateTimer(1.0,mana,_,TIMER_REPEAT);
	CreateTimer(1.0,ultimate,_,TIMER_REPEAT);
	MoneyOffsetCS=FindSendPropInfo("CCSPlayer","m_iAccount");
	m_vecBaseVelocity = FindSendPropOffs("CBasePlayer","m_vecBaseVelocity");
}

public OnMapStart()
{
BurnSprite=PrecacheModel("materials/sprites/fire1.vmt");
ShieldSprite=PrecacheModel("sprites/strider_blackball.vmt");
BeamSprite=PrecacheModel("materials/sprites/lgtning.vmt");
HaloSprite=PrecacheModel("materials/sprites/halo01.vmt");
War3_PrecacheSound(frost);
War3_PrecacheSound(fire);
War3_PrecacheSound(shield);
War3_PrecacheSound(tornado);
War3_PrecacheSound(lightning);
War3_PrecacheSound(pressure);
}

public OnWar3LoadRaceOrItemOrdered(num)
{
	if(num==170){
		thisRaceID=War3_CreateNewRace("RogueWizard", "RogueWizard");
		SKILL_TRAINING=War3_AddRaceSkill(thisRaceID,"Adept Training", "Become a better wizard",false,8);
		SKILL_SHIELD=War3_AddRaceSkill(thisRaceID,"Mana Shield","Sacrifice mana to protect yourself from damage",false,6);
		SKILL_FIREBALL=War3_AddRaceSkill(thisRaceID,"Fireball (Ability)","Create a fire ball and throw it at your enemy",false,7);
		SKILL_LIGHTNING=War3_AddRaceSkill(thisRaceID,"Forked Lightning (Ability1)","Shock your enemies",false,8);
		SKILL_FROST=War3_AddRaceSkill(thisRaceID,"Orb of Frost (Ability2)","Create a ball of pure ice and attack your enemy",false,6);
		SKILL_TORNADO=War3_AddRaceSkill(thisRaceID,"Tornado (Ability3)","Summon a tornado to stun people who are close to you",false,7);
		ULT_PRESSURE=War3_AddRaceSkill(thisRaceID,"Magical Pressure (Ultimate)","Damage your health for a short time to increase mana generation",true,5);
		War3_CreateRaceEnd(thisRaceID);
	}
}

public OnRaceChanged(client, oldrace, newrace)
{
	if(newrace != thisRaceID){
		War3_WeaponRestrictTo(client,thisRaceID,"");
		W3ResetAllBuffRace(client,thisRaceID);
	}
	
	if(newrace == thisRaceID){
		War3_WeaponRestrictTo(client,thisRaceID,"weapon_knife");
		if(ValidPlayer(client,true)){
			GivePlayerItem(client, "weapon_knife");
		}
		
	}
	
}

stock GetMoney(player)
{
	return GetEntData(player,MoneyOffsetCS);
}

stock SetMoney(player,money)
{
	SetEntData(player,MoneyOffsetCS,money);
}

public OnWar3EventSpawn(client)
{	
	if(War3_GetRace(client)==thisRaceID){
		bOrb[client]=false;
		SetMoney(client,0);
		bShield[client]=true;
		bIsPressure[client]=false;
		bWasPressure[client]=false;
	}
	
}

public OnWar3EventDeath(victim,attacker)
{
	new race=War3_GetRace(victim);
	
	if(race==thisRaceID){
		SetMoney(victim,0);
	}
	
}

public OnW3TakeDmgBullet(victim,attacker,Float:damage)
{
	if(IS_PLAYER(victim)&&IS_PLAYER(attacker)&&victim>0&&attacker>0&&attacker!=victim){
		new vteam=GetClientTeam(victim);
		new ateam=GetClientTeam(attacker);
		
		if(vteam!=ateam){
			new race_attacker=War3_GetRace(attacker);
			new skill_frost=War3_GetSkillLevel(attacker,thisRaceID,SKILL_FROST);
			// Orb of frost
			if(race_attacker==thisRaceID && skill_frost>0 && bOrb[attacker]){
				if(!W3HasImmunity(victim,Immunity_Skills)){
					new Float:speedDown=W3GetBuff(victim,fSlow,War3_GetRace(victim));
					new Float:speedUp=W3GetBuff(victim,fMaxSpeed,War3_GetRace(victim));
					new Float:attack=W3GetBuff(victim,fAttackSpeed,War3_GetRace(victim));
					
					bAttack[victim]=attack;
					bSpeedDown[victim]=speedDown;
					bSpeedUp[victim]=speedUp;
					War3_DealDamage(victim,FrostDamage[skill_frost],attacker,DMG_BULLET,"Orb of Frost");
					War3_SetBuff(victim,fAttackSpeed,War3_GetRace(victim),FrostEff[skill_frost]);
					War3_SetBuff(victim,fSlow,War3_GetRace(victim),FrostEff[skill_frost]);
					EmitSoundToAll(frost,attacker);
					EmitSoundToAll(frost,victim);
					CreateTimer(5.0,Orb,victim);
				}
				
			}
			
		}
		
	}
	
}

public OnW3TakeDmgAll(victim,attacker,Float:damage)
{
	if(IS_PLAYER(victim)&&IS_PLAYER(attacker)&&victim>0&&attacker>0&&attacker!=victim){
		new vteam=GetClientTeam(victim);
		new ateam=GetClientTeam(attacker);
		
		if(vteam!=ateam){
			new race_victim=War3_GetRace(victim);
			new skill_shield=War3_GetSkillLevel(victim,thisRaceID,SKILL_SHIELD);
			new Float:chance_mod=W3ChanceModifier(victim);
			
			if(race_victim==thisRaceID && skill_shield>0 && bShield[victim]){
				if(GetRandomFloat(0.0,1.0)<=ShieldChance[skill_shield]*chance_mod){
					new Float:pos[3];
					new money=GetMoney(victim);
					new ddamage=RoundFloat(damage*DamageDeplete[skill_shield]);
					
					GetClientAbsOrigin(victim,pos);
					pos[2]+=35;
					TE_SetupGlowSprite(pos, ShieldSprite, 0.1, 1.0, 130);
					TE_SendToAll();
					EmitSoundToAll(shield,attacker);
					EmitSoundToAll(shield,victim);
					if(money>=ddamage){
						new new_money;
						
						War3_DamageModPercent(0.0);
						new_money=money-ddamage;
						SetMoney(victim,new_money);
					}
					else
					{
						SetMoney(victim,0);
						War3_DamageModPercent(DamageReducer[skill_shield]);
						PrintHintText(victim,"Mana Shield: Depleted!");
						bShield[victim]=false;
						CreateTimer(5.0, Shield, victim);
					}
					
				}
				
			}
			
		}
		
	}
	
}

public Action:Shield(Handle:timer,any:victim)
{
	bShield[victim]=true;
}

public Action:mana(Handle:timer,any:client)
{
	if(thisRaceID>0){
		for(new i=1;i<=MaxClients;i++){
			if(ValidPlayer(i,true)){
				if(War3_GetRace(i)==thisRaceID){
					new skill_training=War3_GetSkillLevel(i,thisRaceID,SKILL_TRAINING);
					new money=GetMoney(i);
					if(money<MoneyMax[skill_training]){
						if(bWasPressure[i]){
							SetMoney(i,money+MoneyGain[skill_training]/2);
						}
						else
						{
							if(!bIsPressure[i]){
								SetMoney(i,money+MoneyGain[skill_training]);
							}
							else
							{
								SetMoney(i,money+PressureMana);
							}
						}
					}
					else
					{
						if(bIsPressure[i]){
						SetMoney(i,money+PressureMana);
						}
					}
					
				}
				
			}
			
		}
		
	}
	
}

public Action:ultimate(Handle:timer,any:client)
{
	if(thisRaceID>0){
		for(new i=1;i<=MaxClients;i++){
			if(ValidPlayer(i,true)){
				if(War3_GetRace(i)==thisRaceID){
					if(bWasPressure[i]){
						War3_HealToMaxHP(i,PressureHealth);
					}
					else
					{
						if(bIsPressure[i]){
							War3_DealDamage(i,PressureHealth,i,DMG_BULLET,"Magical Pressure");
						}
						
					}
					
				}
				
			}
			
		}
		
	}
	
}

public Action:Restrict(Handle:timer,any:userid)
{
	new client=GetClientOfUserId(userid);
	
	if(client>0){
		bOrb[client]=false;
		War3_WeaponRestrictTo(client,thisRaceID,"weapon_knife");
	}
	
}

public Action:Orb(Handle:timer,any:victim)
{
	if (ValidPlayer(victim,true)){
		new Float:speedUp=bSpeedUp[victim];
		new Float:speedDown=bSpeedDown[victim];	
		new Float:attack=bAttack[victim];
		
		if(speedDown<1){
			War3_SetBuff(victim,fSlow,War3_GetRace(victim),speedDown);
		}
		
		if(speedUp>1){
			War3_SetBuff(victim,fMaxSpeed,War3_GetRace(victim),speedUp);
		}
		
		War3_SetBuff(victim,fAttackSpeed,War3_GetRace(victim),attack);
	}
	
}

public Action:Stop(Handle:timer,any:client)
{
	StopSound(client,SNDCHAN_AUTO,lightning);
}

public OnAbilityCommand(client,ability,bool:pressed)
{
	if(!Silenced(client)){
		if(War3_GetRace(client)==thisRaceID && ability==0 && pressed && IsPlayerAlive(client)){
			if(War3_SkillNotInCooldown(client,thisRaceID,SKILL_FIREBALL,true)){
				new money=GetMoney(client);
				new target = War3_GetTargetInViewCone(client,9000.0,false,10.0);
				new skill_training=War3_GetSkillLevel(client,thisRaceID,SKILL_TRAINING);
				new skill_fire=War3_GetSkillLevel(client,thisRaceID,SKILL_FIREBALL);
					
				if(skill_fire>0){
					if(money>=FireCost[skill_fire]){			
						EmitSoundToAll(fire,client);
						SetMoney(client,money-FireCost[skill_fire]);
						War3_CooldownMGR(client,Cooldown[skill_training],thisRaceID,SKILL_FIREBALL,_,_);
						if(target>0 && !W3HasImmunity(target,Immunity_Skills)){
							new Float:origin[3];
							new Float:targetpos[3];
							
							GetClientAbsOrigin(target,targetpos);
							GetClientAbsOrigin(client,origin);
							TE_SetupBeamPoints(origin, targetpos, BurnSprite, BurnSprite, 0, 5, 1.0, 4.0, 5.0, 2, 2.0, {255,128,35,255}, 70);  
							TE_SendToAll();
							GetClientAbsOrigin(target,targetpos);
							targetpos[2]+=50;
							TE_SetupGlowSprite(targetpos,BurnSprite,1.0,1.9,255);
							TE_SendToAll();
							EmitSoundToAll(fire,target);
							War3_DealDamage(target,FireDamage[skill_fire],client,DMG_BULLET,"Fireball");
							IgniteEntity(target, FireTime[skill_fire]);
						}
						else
						{
							new Float:origin[3];
							new Float:targetpos[3];
							
							War3_GetAimEndPoint(client,targetpos);
							GetClientAbsOrigin(client,origin);
							TE_SetupBeamPoints(origin, targetpos, BurnSprite, BurnSprite, 0, 5, 1.0, 4.0, 5.0, 2, 2.0, {255,128,35,255}, 70);  
							TE_SendToAll();
							War3_GetAimEndPoint(client,targetpos);
							targetpos[2]+=50;
							TE_SetupGlowSprite(targetpos,BurnSprite,1.0,1.9,255);
							TE_SendToAll();
						}
						
					}
					else
					{
					PrintHintText(client, "You don't have enough mana");
					}
					
				}
				else
				{
					PrintHintText(client, "Level your fireball first");
				}
				
			}
			
		}
		
		if(War3_GetRace(client)==thisRaceID && ability==1 && pressed && IsPlayerAlive(client)){
			if(War3_SkillNotInCooldown(client,thisRaceID,SKILL_LIGHTNING,true)){
				new skill_training=War3_GetSkillLevel(client,thisRaceID,SKILL_TRAINING);
				new money=GetMoney(client);
				new skill_lightning=War3_GetSkillLevel(client,thisRaceID,SKILL_LIGHTNING);
				
				if(skill_lightning>0){
					if(money>=LightningCost[skill_lightning]){
						for(new x=0;x<MAXPLAYERS;x++)
							bBeenHit[client][x]=false;
							
						new target = War3_GetTargetInViewCone(client,LightningDistance[skill_lightning],false,20.0);
						
						if(target>0 && !W3HasImmunity(target,Immunity_Skills)){
							new Float:distance=LightningDistance[skill_lightning];
							new Float:target_pos[3];
							new Float:start_pos[3];
							
							GetClientAbsOrigin(target,target_pos);						
							GetClientAbsOrigin(client,start_pos);
							TE_SetupBeamPoints(start_pos,target_pos,BeamSprite,BeamSprite,0,35,1.0,40.0,40.0,0,40.0,{255,100,255,255},40);
							TE_SendToAll();
							EmitSoundToAll(lightning,client,SNDCHAN_AUTO);
							CreateTimer(2.0, Stop, client);
							DoChain(client,distance,LightningDamage[skill_lightning],true,0);
							War3_CooldownMGR(client,Cooldown[skill_training],thisRaceID,SKILL_LIGHTNING,_,_);
						}
						else
						{
							PrintHintText(client, "Not Close enough");
						}
						
					}
					else
					{
						PrintHintText(client, "You don't have enough mana");
					}
					
				}
				else
				{
					PrintHintText(client, "Level your forked lightning first");
				}
				
			}
			
		}
		
		if(War3_GetRace(client)==thisRaceID && ability==2 && pressed && IsPlayerAlive(client)){
			if(War3_SkillNotInCooldown(client,thisRaceID,SKILL_FROST,true)){
				new money=GetMoney(client);
				new skill_frost=War3_GetSkillLevel(client,thisRaceID,SKILL_FROST);
				new skill_training=War3_GetSkillLevel(client,thisRaceID,SKILL_TRAINING);
					
				if(skill_frost>0){
					if(money>=FrostCost[skill_frost]){
						SetMoney(client,money-FrostCost[skill_frost]);
						War3_WeaponRestrictTo(client,thisRaceID,"weapon_knife,weapon_hegrenade");
						GivePlayerItem(client,"weapon_hegrenade");
						bOrb[client]=true;
						CreateTimer(5.0,Restrict,GetClientUserId(client));
						War3_CooldownMGR(client,Cooldown[skill_training],thisRaceID,SKILL_FROST,_,_);
					}
					else
					{
						PrintHintText(client, "You don't have enough mana");
					}
					
				}
				else
				{
					PrintHintText(client, "Level your orb of Frost first");
				}
				
			}
			
		}
		
		if(War3_GetRace(client)==thisRaceID && ability==3 && pressed && IsPlayerAlive(client)){
			if(War3_SkillNotInCooldown(client,thisRaceID,SKILL_TORNADO,true)){
				new skill_training=War3_GetSkillLevel(client,thisRaceID,SKILL_TRAINING);
				new money=GetMoney(client);
				new skill_tornado=War3_GetSkillLevel(client,thisRaceID,SKILL_TORNADO);
				
				if(skill_tornado>0){
					if(money>=TornadoCost[skill_tornado]){
						new Float:position[3];
						
						EmitSoundToAll(tornado,client);
						SetMoney(client,money-TornadoCost[skill_tornado]);
						War3_CooldownMGR(client,Cooldown[skill_training],thisRaceID,SKILL_TORNADO,_,_);
						GetClientAbsOrigin(client, position);
						position[2]+=10;
						TE_SetupBeamRingPoint(position,0.0,TornadoRange[skill_tornado]*2.0,BeamSprite,HaloSprite,0,15,0.3,20.0,3.0,{100,100,150,255},20,0);
						TE_SendToAll();
						GetClientAbsOrigin(client,position);
						TE_SetupBeamRingPoint(position, 20.0, 80.0,BeamSprite,BeamSprite, 0, 5, 2.6, 20.0, 0.0, {54,66,120,100}, 10,FBEAM_HALOBEAM);
						TE_SendToAll();
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 40.0, 100.0,BeamSprite,BeamSprite, 0, 5, 2.4, 20.0, 0.0, {54,66,120,100}, 10,FBEAM_HALOBEAM);
						TE_SendToAll();
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 60.0, 120.0,BeamSprite,BeamSprite, 0, 5, 2.2, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 80.0, 140.0,BeamSprite,BeamSprite, 0, 5, 2.0, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();	
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 100.0, 160.0,BeamSprite,BeamSprite, 0, 5, 1.8, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();	
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 120.0, 180.0,BeamSprite,BeamSprite, 0, 5, 1.6, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();	
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 140.0, 200.0,BeamSprite,BeamSprite, 0, 5, 1.4, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();	
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 160.0, 220.0,BeamSprite,BeamSprite, 0, 5, 1.2, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();	
						position[2]+=20.0;
						TE_SetupBeamRingPoint(position, 180.0, 240.0,BeamSprite,BeamSprite, 0, 5, 1.0, 20.0, 0.0, {54,66,120,100}, 10, FBEAM_HALOBEAM);
						TE_SendToAll();
						for(new i=0;i<=MaxClients;i++){
							if(ValidPlayer(i,true)&&i!=client){
								new clientteam=GetClientTeam(client);
								new iteam=GetClientTeam(i);
					
								if(iteam!=clientteam){
									new Float:iPosition[3];
									new Float:clientPosition[3];
								
									GetClientAbsOrigin(i, iPosition);
									GetClientAbsOrigin(client, clientPosition);
									if(!W3HasImmunity(i,Immunity_Skills)){
										if(GetVectorDistance(iPosition,clientPosition)<TornadoRange[skill_tornado]){
											new Float:velocity[3];
									
											velocity[2]+=800.0;
											SetEntDataVector(i,m_vecBaseVelocity,velocity,true);									
											CreateTimer(0.1,Tornado1,i);
											CreateTimer(0.4,Tornado2,i);
											CreateTimer(1.0,Stun,i);
											CreateTimer(TornadoTime[skill_tornado]+2.0,Unstunned,i);
										}
										
									}
									
								}
								
							}
							
						}
						
					}
					else
					{
						PrintHintText(client, "You don't have enough mana");
					}
					
				}
				else
				{
					PrintHintText(client, "Level your tornado first");
				}
				
			}
			
		}
		
	}
	else
	{
		PrintHintText(client,"Silenced: Can not cast");
	}
	
}

public DoChain(client,Float:distance,dmg,bool:first_call,last_target)
{
	new target=0;
	new Float:target_dist=distance+1.0;
	new caster_team=GetClientTeam(client);
	new Float:start_pos[3];
	new skill_lightning=War3_GetSkillLevel(client,thisRaceID,SKILL_LIGHTNING);
	
	if(last_target<=0)
		GetClientAbsOrigin(client,start_pos);
	else
		GetClientAbsOrigin(last_target,start_pos);
		
	for(new x=1;x<=MaxClients;x++){
		if(ValidPlayer(x,true)&&!bBeenHit[client][x]&&caster_team!=GetClientTeam(x)&&!W3HasImmunity(x,Immunity_Skills)){
			new Float:this_pos[3];
			
			GetClientAbsOrigin(x,this_pos);
			new Float:dist_check=GetVectorDistance(start_pos,this_pos);
			
			if(dist_check<=target_dist){
				target=x;
				target_dist=dist_check;
			}
			
		}
		
	}
	
	if(target<=0){
	}
	else
	{
		bBeenHit[client][target]=true;
		War3_DealDamage(target,LightningDamage[skill_lightning],client,DMG_ENERGYBEAM,"Forked Lightning");
		start_pos[2]+=30.0;
		new Float:target_pos[3];
		GetClientAbsOrigin(target,target_pos);
		target_pos[2]+=30.0;
		TE_SetupBeamPoints(start_pos,target_pos,BeamSprite,BeamSprite,0,35,1.0,40.0,40.0,0,40.0,{255,100,255,255},40);
		TE_SendToAll();
		EmitSoundToAll(lightning,target,SNDCHAN_AUTO);
		CreateTimer(2.0, Stop, target);
		new new_dmg=RoundFloat(float(dmg)*0.66);
		DoChain(client,distance,new_dmg,false,target);	
	}
	
}

public Action:Tornado1(Handle:timer,any:client)
{
	new Float:velocity[3];
	
	velocity[2]+=4.0;
	velocity[0]-=600.0;
	SetEntDataVector(client,m_vecBaseVelocity,velocity,true);
}

public Action:Tornado2(Handle:timer,any:client)
{
	new Float:velocity[3];
	
	velocity[2]+=4.0;
	velocity[0]+=600.0;
	SetEntDataVector(client,m_vecBaseVelocity,velocity,true);
}

public Action:Stun(Handle:timer,any:i)
{
	War3_SetBuff(i,bBashed,thisRaceID,true);
}

public Action:Unstunned(Handle:timer,any:i)
{
	War3_SetBuff(i,bBashed,thisRaceID,false);
}

public Action:Pressure(Handle:timer,any:player)
{
	new client=GetClientOfUserId(player);
	
	if(client>0){
		new ult_pressure=War3_GetSkillLevel(client,thisRaceID,ULT_PRESSURE);
		
		bIsPressure[client]=false;
		bWasPressure[client]=true;
		CreateTimer(PressureTime[ult_pressure],Healing,GetClientUserId(client));
	}
	
}

public Action:Healing(Handle:timer,any:player)
{
	new client=GetClientOfUserId(player);
	
	if(client>0){
		bWasPressure[client]=false;
	}
	
}

public OnUltimateCommand(client,race,bool:pressed)
{
	if(race==thisRaceID && pressed && ValidPlayer(client)){
		new ult_pressure=War3_GetSkillLevel(client,thisRaceID,ULT_PRESSURE);
		
		if(ult_pressure>0){
			if(!Silenced(client)){
				if(War3_SkillNotInCooldown(client,thisRaceID,ULT_PRESSURE,true)){ 
					EmitSoundToAll(pressure,client);
					bIsPressure[client]=true;
					CreateTimer(PressureTime[ult_pressure],Pressure,GetClientUserId(client));
					War3_CooldownMGR(client,50.0,thisRaceID,ULT_PRESSURE,_,_);
				}
				
			}
			else
			{
				PrintHintText(client, "Silenced can not cast");
			}
			
		}
		else
		{
			PrintHintText(client, "Level your ultimate first");
		}
		
	}
	
}